using System;
using Newtonsoft.Json;
using ycx;

namespace RFS.Domain.PaiShi.Zuhuo
{
    public class ZaHuaItem
    {
        private DateTime? _指令时间;

        public override string ToString()
        {
            return  $"{地块}|{品种}|{长度}";
        }
        public bool IsEmtpy { get; set; } = true;

        public ulong Id { get; set; } = 1.NewSnowflakeId();
        public ulong IdBackPointer  { get; set; }
        public string 扎花打码 { get; set; }
        public string 供货商码 { get; set; }
        public string 地块 { get; set; }
        public string 货品编码 { get; set; }
        public string 品种 { get; set; }
        public string 长度 { get; set; }
        public string 规格 { get; set; }
        public string SKU { get=>$"{地块}_{长度}_{规格}_{ GetDays( 供货日期 )}";   }
        public string SKU别名 { get=>$"{供货商码}_{长度}_{规格}_{  GetDays( 供货日期 ) }";   }

        public int GetDays(DateTime date)
        {
            var b = new DateTime(1900, 1, 1);
            var d= ((int) (date- b ).TotalDays   ) +2  ;

            return d;
        }
        public DateTime 供货日期 { get; set; }= DateTime.Now;

        public DateTime? 指令时间
        {
            get => _指令时间;
            set
            {
                _指令时间 = value;
                 
            }
        }

        public string GroupKey { get=> $"{地块}_{品种}_{长度}_{GetDays( 供货日期 )}"; }
        
        public ulong ZhiLingItemId { get; set; }

        public string 业务类型 { get; set; }
        
        
        [JsonIgnore]
        public bool Changed { get;  set; } = false;
        
        
        [JsonIgnore]
        public ZuhuaZiLingItem ZuhuaZiLingItem { get; set; }

        [JsonIgnore]
        public bool IsSavedInDb { get; set; } = false;


        public void LinkTo(ZuhuaZiLingItem zaItem,ZuhuaRecord zr)
        {
            ZuhuaZiLingItem=zaItem;
            ZhiLingItemId=zaItem.Id;
            指令时间=zr.ZHTime ;
            //Changed = true;
        }        
        public void RemoveZuhua( )
        {
            ZuhuaZiLingItem=new ZuhuaZiLingItem();
            指令时间 = null;
            ZhiLingItemId= 0 ;
            //Changed = true;
        }
    }
}